package gold.digger;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC646 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int findLongestChain(int[][] pairs) {
            if (pairs == null || pairs.length <= 0 || pairs[0].length <= 0) {
                return 0;
            }

            Arrays.sort(pairs, (pair1, pair2) -> (pair1[0] - pair2[0]));
            int length = pairs.length;
            int[] dp = new int[length];
            //Arrays.fill(dp, 1);
            dp[0] = 1;
            int allMax = Integer.MIN_VALUE;
            for (int i = 1; i < length; i++) {
                dp[i] = 1;
                for (int j = 0; j < i; j++) {
                    if (pairs[i][0] > pairs[j][1]) {
                        dp[i] = Math.max(dp[i], dp[j] + 1);
                    }
                }
                allMax = Math.max(allMax, dp[i]);
            }
            return allMax;
        }
    }


    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC646 an = new LC646();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
